package com.phynos.web.manager.controller.ajax;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.phynos.web.manager.json.JsonResult;
import com.phynos.web.manager.json.ResultCodeEnum;

/**
 * json请求 基类，处理一些统一异常
 * @author lupc
 *
 */
public class BaseJsonController {
	
	private static final Logger Log = Logger.getLogger(BaseJsonController.class);
	
	@ResponseBody
	@ExceptionHandler(org.apache.shiro.authz.UnauthorizedException.class)
	public JsonResult handlerUnauthorizedException(
			org.apache.shiro.authz.UnauthorizedException ex,
			HttpServletRequest request){
		Log.warn("无权限的访问：" + ex.getMessage());
		return JsonResult.code(ResultCodeEnum.NOT_HAVE_PERMISSION,request);
	}
	
	@ResponseBody
	@ExceptionHandler(RuntimeException.class)
	public JsonResult handlerException(RuntimeException ex,HttpServletRequest request){
		Log.error(ex.getMessage(), ex);
		return JsonResult.code(ResultCodeEnum.SYSTEM_UNKNOWN_ERROR,request);
	}
	
}
